package com.example.serverdemo.utils.crcutls;

import cn.hutool.core.convert.Convert;
import com.example.serverdemo.utils.stringutils.StringUtils;

import java.util.zip.CRC32;

public class LightControllerCRCUtil {
    public static byte[] getCrc(byte[] data){
        short crc = 0;
        for (int i = 0;i < data.length;i++){
            crc ^= (short) (data[i] << 8);
            for (int j = 0;j < 8;j++){
                if ((crc & 0x80000) != 0x0000){
                    crc <<= 1;
                    crc ^= 0x1021;
                }else {
                    crc <<= 1;
                }
            }
        }
        byte[] crcBuff = Convert.intToBytes(crc);
        return crcBuff;
    }
}
